import Vuex from 'vuex'

const store = new Vuex.Store({
    state: {
        token:'',
        // 状态
        user:{

        }
    },
    getters: {
        // 获取状态
    },
    mutations: {
        SET_TOKEN:(state,token)=>{
            state.token = token
            localStorage.setItem("token",token)
        },
        resetState:(state)=>{
            state.token = ""
        },
        // 修改状态
        SET_USER:(state,user) =>{
            state.user = JSON.parse(JSON.stringify(user)); // 使用JSON进行深拷贝
            localStorage.setItem("user", JSON.stringify(user));
        },
        resetUserState:(state) =>{
            state.user = {}
            localStorage.removeItem("user"); // 从 localStorage 中移除 user
        }
    },
    actions: {
        // 异步操作
    }
})

export default store



